#include "common.h"
namespace common {
std::vector<int> searchRange(std::vector<int> &nums, int target) {
    if (nums.empty())
        return {-1, -1};
    const int N = nums.size();
    int left = 0;
    int right = N - 1;
    int mid = 0;
    std::vector<int> result;
    while (left < right) {
        mid = left + ((right - left) >> 1);
        if (nums[mid] < target)
            left = mid + 1;
        else
            right = mid;
    }
    if (nums[left] != target)
        return {-1, -1};
    result.push_back(left);

    right = N - 1;
    while (left < right) {
        mid = (right + left + 1) / 2;
        if (nums[mid] <= target) {
            left = mid;
        } else {
            right = mid - 1;
        }
    }
    result.push_back(right);
    return result;
}
} // namespace common
